<?php

class edgeDialog {
	public function __construct() {
		parent::__construct();
		
		return;
	}
}

class edgeOptionsDialog extends GtkDialog {

	public $return;

	public function __construct($parent) {
		parent::__construct();
		
		$this->bar = new GtkVSeparator;
		$this->hbox = new GtkHBox;
		$this->optbox = new GtkVBox;
		$this->bufbox = new GtkVBox;
		$this->buf2box = new GtkHBox;
		
		$this->lbllog = new edgeLabel("<b>Log File</b>\n<i>\$s = stream name</i>");
		$this->entlog = new GtkEntry;		
		$this->entlog->set_text(edge::$logfile);
		$this->entlog->set_size_request(200,-1);
		$this->entlog->connect_simple('changed',array($this,'update_tip1'));
		$this->update_tip1();
		
		$this->optlog = new GtkCheckButton('Enable Title Logging');
		$this->optlog->set_active(edge::$logtitle);

		$this->opttray = new GtkCheckButton('Minimize To Tray');
		$this->opttray->set_active(edge::$usetray);

		$this->opttraypop = new GtkCheckButton('Tray Notification on Song Change');
		$this->opttraypop->set_active(edge::$songtraypop);

		$this->buflbl = new edgeLabel('<b>Buffer Options</b>');		
		$this->lblbuf1 = new edgeLabel('Buffer Size (KB)',90);
		$this->optbuf1 = GtkVScale::new_with_range(512,8192,64);
		$this->lblbuf2 = new edgeLabel('Buffer Pre-fill (%)',90);
		$this->optbuf2 = GtkVScale::new_with_range(0,100,0.1);
		$this->lblbuf3 = new edgeLabel('Low Buffer Warning (%)',90);
		$this->optbuf3 = GtkVScale::new_with_range(0,100,1);
		$this->optbuf1->set_inverted(true);
		$this->optbuf1->set_size_request(-1,150);
		$this->optbuf1->set_value(edge::$cachesize);
		$this->optbuf2->set_inverted(true);
		$this->optbuf2->set_value(edge::$cachefill);
		$this->optbuf3->set_inverted(true);
		$this->optbuf3->set_value(edge::$bufferlowthresh * 100);
		
		$this->btncancel = $this->add_button(Gtk::STOCK_CANCEL, Gtk::RESPONSE_CANCEL);
		$this->btnok = $this->add_button(Gtk::STOCK_APPLY, Gtk::RESPONSE_ACCEPT);

		$this->connect_simple(
			'delete-event',
			array($this,'response'),
			Gtk::RESPONSE_CANCEL	
		);

		$this->set_transient_for($parent);
		$this->set_modal(true);
		$this->set_title('edgecast Options');
		$this->set_has_separator(false);

		$this->optbox->pack_start($this->lbllog,false,false,3);
		$this->optbox->pack_start($this->entlog,false,false,3);
		$this->optbox->pack_start($this->optlog,false,false,3);
		$this->optbox->pack_start($this->opttray,false,false,3);
		$this->optbox->pack_start($this->opttraypop,false,false,3);
		$this->buf2box->pack_start($this->lblbuf1,true,true,3);
		$this->buf2box->pack_start($this->optbuf1,true,true,3);
		$this->buf2box->pack_start($this->lblbuf2,true,true,3);
		$this->buf2box->pack_start($this->optbuf2,true,true,3);
		$this->buf2box->pack_start($this->lblbuf3,true,true,3);
		$this->buf2box->pack_start($this->optbuf3,true,true,3);
		$this->bufbox->pack_start($this->buflbl,false,false,3);
		$this->bufbox->pack_start($this->buf2box,true,true,3);
		$this->hbox->pack_start($this->optbox,true,true,0);
		$this->hbox->pack_start($this->bar,false,false,3);
		$this->hbox->pack_start($this->bufbox,false,false,0);
		$this->vbox->pack_start($this->hbox,true,true,0);

		$this->show_all();
		$this->btncancel->grab_focus();
		$this->entlog->select_region(0,0);
		
		$return = $this->run();

		if($return == Gtk::RESPONSE_ACCEPT) {
			
			edge::$logfile = $this->entlog->get_text();
			edge::$logtitle = (boolean)$this->optlog->get_active();
			edge::$cachesize = $this->optbuf1->get_value();
			edge::$cachefill = $this->optbuf2->get_value();
			edge::$usetray = (boolean)$this->opttray->get_active();
			edge::$bufferlowthresh = $this->optbuf3->get_value() / 100;
			edge::$songtraypop = (boolean)$this->opttraypop->get_active();
		
			@mkdir(dirname(edge::$logfile),0777,true);
//			@touch(edge::mkfilesafe(edge::$logfile));
		
			edge::write_config();
//			edge::read_config();
		}

		$this->hide();
		return;
	}
	
	public function update_tip1() {
		$this->entlog->set_tooltip_text(edge::mkfilesafe(
			$this->entlog->get_text()
		));
		return;	
	}
}

?>